clear;
% clc;
%% Setup
ParamInput  =   struct('NU_C',1,'NU_L',1,'KAPPA',0.00/4,'XI',1/82.5/4,'Pir_SS',0.02/4,...
                       'B_Total_SS',0.95,'b_lb',-0.21);
% High FI
% ParamInput.B_Total_SS   =   ParamInput.B_Total_SS/(1-ParamInput.Prob_ext)*(1-0.95);
% ParamInput.Prob_ext     =   0.95;
% % Low FI
% ParamInput.B_Total_SS   =   ParamInput.B_Total_SS/(1-ParamInput.Prob_ext)*(1-0.05);
% ParamInput.Prob_ext     =   0.05;
% High RI
% ParamInput.Cons_FracT   =   0.90;
% Low RI
ParamInput.Cons_FracT   =   0.10;

PP          =   Setup_PP(ParamInput);
%% Steady State
PSI_0       =   1;
FracHN_w_0  =   1;
FracHN_wN_0 =   PP.ExoState.Idio_RI.InvDist(2)/PP.ExoState.Idio_RI.InvDist(1);
DiscFactor_0=   0.02;
SS          =   SteadyState_Solver(PP,PSI_0,FracHN_w_0,DiscFactor_0,FracHN_wN_0);
SS.N_H/(SS.N_H+SS.N_N)
return
%% Wealth and Income Distribution
WI          =   SS_WealthIncome(PP,SS);
%% MPC 
MPC         =   SS_MPC(PP,SS);
%% Summary
Stat_Name       =   {'Wealth, Acc. Share: Top 1%','Wealth, Acc. Share: Top 5%',...
                     'Wealth, Acc. Share: Top 10%','Wealth, Acc. Share: Bottom 5%',...
                     'Prob. of Negative Wealth','Prob. of Zero Wealth',...
                     'Wealth-Income Ratio: 25%','Wealth-Income Ratio: 75%',...
                     'Wealth-Income Ratio: Median','Prob. of HtM',...
                     'Wealth-Income Ratio: Average',...
                     'MPC: 5%','MPC: 25%','MPC: 75%','MPC: 95%',...
                     'MPC: Median','MPC: Average',...
                     'Median Wealth/Median Income'};
Stat_Value_Model=   [WI.Wealth.TopShare(1:3);1-WI.Wealth.TopShare(end-1);...
                     WI.Wealth.Frac_Neg;WI.Wealth.Frac_Zero;...
                     WI.WealthIncomeRatio.Quant([4;6]);...
                     WI.WealthIncomeRatio.Quant(5);WI.WealthIncomeRatio.Share_HtM;...
                     WI.WealthIncomeRatio.Avg;...
                     MPC.Quant([1;3;5;7]);...
                     MPC.Quant(4);MPC.Avg;...
                     WI.Wealth.Median/WI.Income.Median];
Stat_Value_Data =   [[0.41;0.73;0.86;-0.02;0.22;0.02];... % Wealth Distribution
                     [0.00;0.54;0.09]*4;0.40;2.18*4;... % Wealth-Income Distribution
                     [NaN;NaN;NaN;NaN;NaN];0.50;... % MPC
                     0.08*4];
StatTable       =   array2table([Stat_Value_Model,Stat_Value_Data],...
                                'RowNames',Stat_Name,...
                                'VariableNames',{'Model','Data'});

% display(StatTable);

%% Target Statistics
Stat_Name       =   {'Prob. of Negative Wealth',...
                     'Median Wealth/Median Income',...
                     'Wealth-Income Ratio: Median',...
                     'Prob. of HtM',...
                     'MPC: Median','MPC: Average' ...
                     };
Stat_Value_Model=   [WI.Wealth.Frac_Neg;...
                     WI.Wealth.Median/WI.Income.Median;...
                     WI.WealthIncomeRatio.Quant(5);...
                     WI.WealthIncomeRatio.Share_HtM;...
                     MPC.Quant(4);MPC.Avg ...
                     ];
Stat_Value_Data =   [0.22;0.08*4;0.304;0.40;NaN;0.5];
TargetStatTable =   array2table([Stat_Value_Model,Stat_Value_Data],...
                                'RowNames',Stat_Name,...
                                'VariableNames',{'Model','Data'});

display(TargetStatTable);

% save('WealthDistribution.mat','PP','SS','Stat');